package com.chasmcity.munrobagging.model;

import java.io.Serializable;

import android.location.Address;
import android.location.Location;

import com.google.android.maps.GeoPoint;

/**
 * TODO: Missing class description for LatLong!
 * <p>
 * &copy; Copyright 2010 Kizoom Ltd.
 * <p>
 * $Id: LatLong.java,v 1.3 2011/02/15 17:09:27 davids Exp $
 */
public class LatLong implements Serializable {

	private final double latitude;
	private final double longitude;
	static private final int E6 = 1000000;
	
	public LatLong(Location location) {
		this(location.getLatitude(), location.getLongitude());
	}
	
	public LatLong(Address address) {
		this(address.getLatitude(), address.getLongitude());
	}

	public LatLong(double latitude, double longitude) {
		this.latitude = latitude;
		this.longitude = longitude;
	}
	
	public LatLong(GeoPoint geoPoint) {
		this((double)geoPoint.getLatitudeE6() / E6, (double)geoPoint.getLongitudeE6() / E6);
	}

	public double getLatitude() {
		return latitude;
	}
	
	public double getLongitude() {
		return longitude;
	}
	
	public int getLatitudeE6() {
		return (int)(latitude * E6);
	}
	
	public int getLongitudeE6() {
		return (int)(longitude * E6);
	}
	
	public GeoPoint asGeoPoint() {
		return new GeoPoint((int)(latitude * 1E6), (int)(longitude * 1E6));
	}
	
	@Override
	public String toString() {
		return String.format("%s,%s", latitude, longitude);
	}
}
